package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.ext.CustomerCommunicateEntityExt;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.sort.SortOrder;

import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/24 21:15
 * @since v1.0
 */
public interface CustomerCommunicateModel extends IModel<CustomerCommunicateEntityExt> {
    /**
     * 客户跟进记录数据插入
     * @param entity 客户跟进记录实体
     * @throws XbbException 异常
     * @return Integer
     * @author long.rao
     * @date 2019-02-01 15:36
     */
    @Override
    Integer insert(CustomerCommunicateEntityExt entity) throws XbbException;
    /**
     * 客户跟进记录数据更新
     * @param entity 客户跟进记录实体
     * @author long.rao
     * @date 2019-02-01 15:36
     * @throws XbbException 异常
     * @return Integer
     */
    @Override
    Integer update(CustomerCommunicateEntityExt entity) throws XbbException;
    /**
     * 客户跟进记录数据查询多个
     * @param param 参数
     * @author long.rao
     * @date 2019-02-01 15:36
     * @return List<CustomerCommunicateEntityExt>
     */
    @Override
    List<CustomerCommunicateEntityExt> findEntitys(Map<String, Object> param);

    List<CustomerCommunicateEntityExt> findNotAutGenEntitys(Map<String, Object> param);
    /**
     * 客户跟进记录数据查询条数
     * @param param 参数
     * @author long.rao
     * @date 2019-02-01 15:36
     * @return Integer
     */
    @Override
    Integer getEntitysCount(Map<String, Object> param);
    /**
     * 客户跟进记录数据单条查询
     * @param key 主键ID
     * @param corpid 公司ID
     * @author long.rao
     * @date 2019-02-01 15:36
     * @return Integer
     */
    CustomerCommunicateEntityExt getByKey(Long key, String corpid);

    List<CustomerCommunicateEntityExt> getByIdIn(List<Long> idIn, String corpid);

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/2/17 14:58
     * @param idIn id列表
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException
     */
    Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    /**
     * 批量插入
     * @author 吴峰
     * @date 2019/3/19 20:15
     * @param customerCommunicateList
     * @return
     * @throws XbbException 业务异常
     */
    List<CustomerCommunicateEntityExt> insertBatch(List<CustomerCommunicateEntityExt> customerCommunicateList) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateDataList, String corpid) throws XbbException;

    /**
     * 数据还原
     * @author xingxing.xiao
     */
    Integer restoreBatch(List<Long> dataIdList, String corpid, Integer del) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    List<CustomerCommunicateEntityExt> findEntitysWithoutSub(Map<String, Object> param);

    List<CustomerCommunicateEntityExt> findNotAutGenEntitysWithoutSub(Map<String, Object> param);

    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 客户跟进记录单编辑格式化数据格式
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 参数格式错误异常
     * @author long.rao
     * @date 2019-01-29 16:23
     */
    void formatData(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatUpdateExplainForDistributor(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 客户跟进记录单编辑格式化数据格式
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 参数格式错误异常
     * @author long.rao
     * @date 2019-01-29 16:23
     */
    void formatDataForDistributor(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;
    /**
     * 客户跟进记录数据插入  使用时间
     * @param entity 客户跟进记录实体
     * @throws XbbException 异常
     * @return Integer
     * @author long.rao
     * @date 2019-02-01 15:36
     */
    Integer insertByTime(CustomerCommunicateEntityExt entity) throws XbbException;

    /**
     * 获取客户的跟进记录
     *
     * @param corpid     公司id
     * @param linkId 关联字段的值
     * @param customerCommunicateEnum 关联字段
     * @param clazz 返回的实体
     * @param orderField 排序字段 示例：如果是data中的字段，请用data.text_1，data外则无需data.
     * @see SortOrder
     * @param sortOrder 排序
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/11 11:10
     * @since V1.0
     * @throws XbbException
     */
    <T> List<T> getCustomerCommunicateListByLinkId(String corpid, Long linkId, CustomerCommunicateEnum customerCommunicateEnum, Class<T> clazz, String orderField, SortOrder sortOrder) throws XbbException;

    /**
     * 获取客户的跟进记录
     *
     * @param corpid     公司id
     * @param boolQueryBuilder 关联字段
     * @param clazz 返回的实体
     * @param orderField 排序字段 示例：如果是data中的字段，请用data.text_1，data外则无需data.
     * @see SortOrder
     * @param sortOrder 排序
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/11 11:10
     * @since V1.0
     * @throws XbbException
     */
    <T> List<T> getCustomerCommunicateListByBoolQuery(String corpid, BoolQueryBuilder boolQueryBuilder, Class<T> clazz, String orderField, SortOrder sortOrder) throws XbbException;


    /**
     * 获取最大id 刷脚本用
     * date: 2022/7/12 6:48 下午
     * @author yingjf
     * @param :
     */
    Long getMaxId()throws XbbException;
}
